package cn.buk.tms.flight.dto;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class FareBasisDto {

  /**
   * 票价基础代码
   */
  private String fareBasisCode;

  private String fareRule;

  private double minAdultPrice;

  private List<FareInfoDto> fareInfos;

  /**
   * 乘机人类型集，确保一个乘机人类型在fareInfos中只增加一次
   */
//  private Set<String> psgTypeSet = new HashSet<>();

  public void addFareInfo(FareInfoDto fi) {
//    if (!psgTypeSet.contains(fi.getPsgType())) {
//      psgTypeSet.add(fi.getPsgType());
      this.getFareInfos().add(fi);

      if ("ADT".equalsIgnoreCase(fi.getPsgType())) {
        if (minAdultPrice == 0) {
          minAdultPrice = fi.getBaseAmount();
        } else if (minAdultPrice > fi.getBaseAmount()) {
          minAdultPrice = fi.getBaseAmount();
        }
      }
//    }
  }

  public String getPsgType() {
    return getFareInfos().size() > 0 ? getFareInfos().get(0).getPsgType(): null;
  }

  public List<FareInfoDto> getFareInfos() {
    if (fareInfos == null) {
      fareInfos = new ArrayList<>();
    }
    return fareInfos;
  }

  public void setFareInfos(List<FareInfoDto> fareInfos) {
    this.fareInfos = fareInfos;
  }


  public String getFareRule() {
    return fareRule;
  }

  public void setFareRule(String fareRule) {
    this.fareRule = fareRule;
  }

  public String getFareBasisCode() {
    return fareBasisCode;
  }

  public void setFareBasisCode(String fareBasisCode) {
    this.fareBasisCode = fareBasisCode;
  }

  public double getMinAdultPrice() {
    return minAdultPrice;
  }
}
